package com.xsdl.chain.verifier;

import cn.hutool.core.exceptions.ValidateException;

import java.util.ArrayList;
import java.util.List;

public class ValidatorContext {

    private List<String> errMsgs;

    private Object bean;

    private boolean stop;

    public ValidatorContext(Object bean) {
        this.bean = bean;
        this.stop = false;
        this.errMsgs = new ArrayList<>();
    }

    public void appendErrMsg(String msg) {
        errMsgs.add(msg);
    }

    public String getErrMsg() {
        return errMsgs.toString();
    }

    public void stop() {
        stop = true;
    }

    public boolean getStop() {
        return this.stop;
    }

    public Object getBean() {
        return this.bean;
    }


    public void throwErrMsgIfNecessary() {
        if (errMsgs.size() > 0) {
            throw new ValidateException(errMsgs.toString());
        }
    }

}
